package com.rds.web.controller.pms;

import com.rds.common.annotation.Log;
import com.rds.common.core.controller.BaseController;
import com.rds.common.core.domain.AjaxResult;
import com.rds.common.core.page.TableDataInfo;
import com.rds.common.enums.BusinessType;
import com.rds.common.utils.poi.ExcelUtil;
import com.rds.system.domain.RdaCommand;
import com.rds.system.service.IRdaCommandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * command命令Controller
 *
 * @author rds
 * @date 2021-04-19
 */
@RestController
@RequestMapping("/pms/command")
public class RdaCommandController extends BaseController
{
    @Autowired
    private IRdaCommandService rdaCommandService;

    /**
     * 查询command命令列表
     */
    @PreAuthorize("@ss.hasPermi('pms:command:list')")
    @GetMapping("/list")
    public TableDataInfo list(RdaCommand rdaCommand)
    {
        startPage();
        List<RdaCommand> list = rdaCommandService.selectRdaCommandList(rdaCommand);
        return getDataTable(list);
    }

    /**
     * 查询command命令列表
     */
    @PreAuthorize("@ss.hasPermi('pms:command:getList')")
    @GetMapping("/getList")
    public AjaxResult getList(RdaCommand rdaCommand)
    {
        return AjaxResult.success(rdaCommandService.selectRdaCommandList(rdaCommand));
    }
    /**
     * 查询portal区域command命令列表
     */
    @PreAuthorize("@ss.hasPermi('pms:command:getList')")
    @GetMapping("/portal/{fromid}")
    public AjaxResult portal(@PathVariable("fromid") Long fromid)
    {
        return AjaxResult.success(rdaCommandService.selectByPortal(fromid));
    }

    /**
     * 导出command命令列表
     */
    @PreAuthorize("@ss.hasPermi('pms:command:export')")
    @Log(title = "command命令", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RdaCommand rdaCommand)
    {
        List<RdaCommand> list = rdaCommandService.selectRdaCommandList(rdaCommand);
        ExcelUtil<RdaCommand> util = new ExcelUtil<RdaCommand>(RdaCommand.class);
        return util.exportExcel(list, "command");
    }

    /**
     * 获取command命令详细信息
     */
    @PreAuthorize("@ss.hasPermi('pms:command:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(rdaCommandService.selectRdaCommandById(id));
    }

    /**
     * 新增command命令
     */
    @PreAuthorize("@ss.hasPermi('pms:command:add')")
    @Log(title = "command命令", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RdaCommand rdaCommand)
    {
        return toAjax(rdaCommandService.insertRdaCommand(rdaCommand));
    }

    /**
     * 修改command命令
     */
    @PreAuthorize("@ss.hasPermi('pms:command:edit')")
    @Log(title = "command命令", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RdaCommand rdaCommand)
    {
        return toAjax(rdaCommandService.updateRdaCommand(rdaCommand));
    }

    /**
     * 删除command命令
     */
    @PreAuthorize("@ss.hasPermi('pms:command:remove')")
    @Log(title = "command命令", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rdaCommandService.deleteRdaCommandByIds(ids));
    }
}
